<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>

	<link rel="stylesheet" href="./Tpl/css/bootstrap.min.css">
	<style type="text/css">
		#zhengtijuz{
			width: 1100px;
			margin: 0 auto;
			margin-top: 100px;
		}
		.zhuti{
			margin: 0 auto;
			margin-top: 100px;
			width: 100%;
			height: 300px;
		}
		body #zhutixia{
			margin: 0 auto;
			width: 1470px;

		}
		.tex{
			margin-top: 20px;
			margin-bottom: 50px;
			height: 100px;
		}
		.form-inline .tex .content{
			width: 100%;
			height: 100%;
		}
		#navbar form{
			padding: 0px 2px;
		}
	</style>
</head>
<body>
	<nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          	<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
	            <span class="sr-only">Toggle navigation</span>
	            <span class="icon-bar"></span>
	            <span class="icon-bar"></span>
	            <span class="icon-bar"></span>
          	</button>
          	<a class="navbar-brand" href="#">留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
        	<?php if (isset($_SESSION['nikename'])) { ?>
        		<div class="navbar-form navbar-right">
	          		<p class="btn btn-danger"><?php echo $_SESSION['nikename'] ?></p>
	          		<a href="./loginout.php" class="btn btn-success">退出</a>
          		</div>		
        	<?php }else{ ?>
<!-- 				<form action="./enroll.php" method="post" class="navbar-form navbar-right">
		<button type="submit" class="btn btn-info">注册</button>
				    </form> -->	
          		<form action="./login.php" method="post" class="navbar-form navbar-right">
		            <div class="form-group">
		              	<input type="text" placeholder="请输入用户名" name='username' class="form-control">
		            </div>
	            <div class="form-group">
	              	<input type="password" placeholder="请输入密码" name='password' class="form-control">
	            </div>
            	<button type="submit" class="btn btn-success">登陆</button>
            	<a class="btn btn-info" href="./enrolln.php">注册</a>
            	<!-- <button type="submit" class="btn btn-success">注册</button> -->
          		</form>
        	<?php } ?>
        	

          	
          
        </div><!--/.navbar-collapse -->
      </div>
    </nav>
	<!-- <nav class="navbar navbar-inverse navbar-fixed-top">
	      <div class="container">
	        <div class="navbar-header">
	          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
	            <span class="sr-only">Toggle navigation</span>
	            <span class="icon-bar"></span>
	            <span class="icon-bar"></span>
	            <span class="icon-bar"></span>
	          </button>
	          <a class="navbar-brand" href="#">留言板</a>
	        </div>
	        <div id="navbar" class="navbar-collapse collapse">
	          <ul class="nav navbar-nav">
	            <li class="active"><a href="#">Home</a></li>
	          </ul>
	        </div>/.nav-collapse
	      </div>
	    </nav> -->
<div id="zhengtijuz">
    <div id="zhuti">
    	<?php foreach ($db as $k => $v) { ?>
    		<div class="alert <?php echo $color[array_rand($color)] ?> delbox" role="alert">
        		<strong>
        			<?php echo $v['username']; ?>
        		</strong>
        			<?php echo $v['content']; ?>（<?php echo date('Y-m-d H:i:s',$v['create_Time']); ?>）
        			<?php if (isset($_SESSION['nikename']) && ($_SESSION['username'])==$v['username']) { ?>
        				<button delid='<?php echo $k ?>' class="btn btn-warning delBtn">删除</button>
        				<a class="btn btn-success" href="./edit.php?id=<?php echo $k ?>">修改</a>
        				<!-- <a class="btn btn-warning" href="./del.php?id=<?php echo $k ?>">删除</a>
        				<a class="btn btn-success" href="./edit.php?id=<?php echo $k ?>">修改</a> -->
        			<?php }?>
        				
      		</div>
    	<?php } ?>
    </div>


    <div class="zhutixia">
    	<?php if (isset($_SESSION['nikename'])) { ?>
       		<form class="form-inline" method="post" action="./add.php">
    		  	<div class="form-group">
    		    	<label for="exampleInputName2"></label>
    		    	<input type="text" class="form-control" name="username" id="exampleInputName2" readonly="true" value="<?php echo $_SESSION['nikename'] ?>">
    		  	</div>
    		  	<button type="submit" class="btn btn-info">留言</button>
    		  	<div class="tex">
    		  		<textarea class="form-control content" name="content" rows="3"></textarea>
    		  	</div>
    		</form>
    		<?php }else{ ?>
			<form class="form-inline" method="post" action="./add.php">
    		  	<div class="form-group">
    		    	<label for="exampleInputName2"></label>
    		    	<input type="text" class="form-control" name="username" id="exampleInputName2" readonly="true" placeholder='用户名'>
    		  	</div>
    		  	<button type="submit" class="btn btn-info" onclick="dj()">留言</button>
    		  	<div class="tex">
    		  		<textarea class="form-control content" name="content" rows="3" placeholder='登陆后留言'></textarea>
    		  	</div>
    		</form>
    		<?php } ?>
    </div>

</div>	
</body>
	<script type="text/javascript" src='./Tpl/js/jquery.min.js'></script>
	<script type="text/javascript">
	$(function (){
		$('.delBtn').click(function(event) {

			var id = $(this).attr('delid');   /*attr设置或返回被选元素的属性值*/
			delBtn=$(this);
			$.ajax({
				url: './ajaxdel.php',
				type: 'POST',
				dataType: 'json',     	/*返回数据类型JS能直接读懂的  不写的话任何类型都可以返回*/
				data: {msgid: id},    	/*发什么数据--要删除的id*/
			})
/*成功*/	.done(function(data) {    	/*定义变量data来放置返回的数据*/
				if (data.error==0) {  	/*data对象里面的error==0*/
				alert(data.info);		/*info==删除成功*/
				delBtn.parents('.delbox').remove();        /*找到祖先并remove删除全部*/
				}   
			})
			.fail(function(data) {
				/*alert('失败');*/
				/*if (data.error==1) {
				alert(data.info);
				}*/
			})
			
			

		});

	})




	function dj()  {
		alert('请登陆后留言');
	}
	</script>
</html>